package com.yourenbang.lingyun.transaction.web.service.impl.pay.withdraw;

import com.yourenbang.lingyun.constants.BizCodeMessages;
import com.yourenbang.lingyun.constants.enums.FundBillType;
import com.yourenbang.lingyun.constants.enums.PlatNoEnums;
import com.yourenbang.lingyun.constants.enums.fund.AccountType;
import com.yourenbang.lingyun.constants.enums.pay.PayFromEnum;
import com.yourenbang.lingyun.core.exception.UserBizException;
import com.yourenbang.lingyun.core.util.date.DateFormat;
import com.yourenbang.lingyun.transaction.web.domain.vo.pay.WithdrawInAmountFeeVO;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.RandomStringUtils;

import java.math.BigDecimal;
import java.time.LocalDateTime;

/**
 * 提现抽象类
 */
@Slf4j
public class WithdrawAccountConfig {

    /**
     * 获取 凌云提现订单号 前缀
     *
     * @param withdrawType 提现类型
     */
    public static String getOrderPrefix(String withdrawType) {
//        if (PayFromEnum.commission.isEquals(withdrawType)) {                        //银行卡推广返佣提现
//            return "LYCS";
//        } else if (PayFromEnum.taobao_score.isEquals(withdrawType)) {               //积分购物返利提现
//            return "LYTB";
//        } else if (PayFromEnum.withdraw_mer.isEquals(withdrawType)) {               //提现-商户账户
//            return "LYMA";
//        } else
        if (PayFromEnum.withdraw_ally.isEquals(withdrawType)) {              //提现-盟友账户
            return "LYAA";
//        } else if (PayFromEnum.withdraw_ally_reach.isEquals(withdrawType)) {        //提现-达标奖励账户
//            return "LYAR";
//        } else if (PayFromEnum.withdraw_ally_profit.isEquals(withdrawType)) {       //提现-收益账户
//            return "LYSY";
//        } else if (PayFromEnum.withdraw_conversion.isEquals(withdrawType)) {        //提现-兑换金账户
//            return "LYDHJ";
//        } else if (PayFromEnum.zyj_commission.isEquals(withdrawType)) {             //众赢嘉-银行卡推广返佣提现
//            return "ZYJLYCS";
//        } else if (PayFromEnum.zyj_taobao_score.isEquals(withdrawType)) {           //众赢嘉-积分购物返利提现
//            return "ZYJLYTB";
//        } else if (PayFromEnum.zyj_withdraw_ally.isEquals(withdrawType)) {          //众赢嘉-提现-盟友账户
//            return "ZYJLYAA";
//        } else if (PayFromEnum.zyj_withdraw_ally_reach.isEquals(withdrawType)) {    //众赢嘉-提现-达标奖励账户
//            return "ZYJLYAR";
//        } else if (PayFromEnum.zyj_ally_profit.isEquals(withdrawType)) {            //众赢嘉-提现-收益账户
//            return "ZYJLYSY";
        } else if (PayFromEnum.yxy_withdraw_mer.isEquals(withdrawType)) {           //银小云-商户账户
            return "YXYLYMA";
        } else if (PayFromEnum.yxy_withdraw_ally.isEquals(withdrawType)) {          //银小云-提现-盟友账户
            return "YXYLYAA";
//        } else if (PayFromEnum.yxy_withdraw_ally_reach.isEquals(withdrawType)) {    //银小云-提现-达标奖励账户
//            return "YXYLYAR";
//        } else if (PayFromEnum.yxy_withdraw_ally_profit.isEquals(withdrawType)) {   //银小云-提现-收益账户
//            return "YXYLYSY";
//        } else if (PayFromEnum.yxy_commission.isEquals(withdrawType)) {   //银小云-提现-信用卡返佣
//            return "YXYLYCS";
//        } else if (PayFromEnum.yxy_sub_teanm.isEquals(withdrawType)) {   //银小云-提现-活跃度
//            return "YXYLYST";
//        } else if (PayFromEnum.client_admin_withdraw.isEquals(withdrawType)) {   //银小云-基梯-提现-返现
//            return "YXYJTAA";
//        } else if (PayFromEnum.client_admin_withdraw_profit.isEquals(withdrawType)) {   //银小云-基梯-提现-分润
//            return "YXYJTSY";
        } else if (PayFromEnum.yxy_withdraw_ally_all.isEquals(withdrawType)) {   //银小云-盟友账户合并提现
            return "YXYLYCAA";
        }
        return "OTHER";

    }

    /**
     * 获取 系统-提现账户类型
     *
     * @param withdrawType 提现类型
     * @return 系统提现账户类型
     * @see AccountType
     */
    public static Integer formatSysAccountType(String withdrawType, Short platNo) {
//        if (PayFromEnum.commission.isEquals(withdrawType)                                           //银行卡推广返佣提现
//                || PayFromEnum.zyj_commission.isEquals(withdrawType)
//                || PayFromEnum.yxy_commission.isEquals(withdrawType)) {                             //众赢嘉-银行卡推广返佣提现
//            return AccountType.getFullCode(AccountType.CREDIT_COMMISSION_WITHDRAW, platNo);
//        } else if (PayFromEnum.taobao_score.isEquals(withdrawType)                                  //积分购物返利提现
//                || PayFromEnum.zyj_taobao_score.isEquals(withdrawType)) {                           //众赢嘉-积分购物返利提现
//            return AccountType.getFullCode(AccountType.SHOPPING_WITHDRAW, platNo);
//        } else
            if (PayFromEnum.yxy_withdraw_mer.isEquals(withdrawType)) {                           //银小云-提现-商户账户
            return AccountType.getFullCode(AccountType.MER_WITHDRAW, platNo);
        } else if (PayFromEnum.withdraw_ally.isEquals(withdrawType)                                 //提现-盟友账户
                    || PayFromEnum.yxy_withdraw_ally.isEquals(withdrawType)) {                          //银小云-提现-盟友账户
            return AccountType.getFullCode(AccountType.ALLY_WITHDRAW, platNo);
//        } else if (PayFromEnum.withdraw_ally_reach.isEquals(withdrawType)                           //提现-达标奖励账户
//                || PayFromEnum.zyj_withdraw_ally_reach.isEquals(withdrawType)                       //众赢嘉-提现-达标奖励账户
//                || PayFromEnum.yxy_withdraw_ally_reach.isEquals(withdrawType)) {                    //银小云-提现-达标奖励账户
//            return AccountType.getFullCode(AccountType.ALLY_REACHWITHDRAW, platNo);
//        } else if (PayFromEnum.withdraw_conversion.isEquals(withdrawType)) {                        //提现-兑换金账户
//            return AccountType.getFullCode(AccountType.CONVERSION, platNo);
//        } else if (PayFromEnum.yxy_sub_teanm.isEquals(withdrawType)) {                        //提现-活跃度账户
//            return AccountType.getFullCode(AccountType.SUB_TEAM_ACTION_WITHDRAW, platNo);
//        } else if (PayFromEnum.withdraw_ally_profit.isEquals(withdrawType)                          //提现-收益账户
//                || PayFromEnum.zyj_ally_profit.isEquals(withdrawType)                               //众赢嘉-提现-收益账户
//                || PayFromEnum.yxy_withdraw_ally_profit.isEquals(withdrawType)) {                   //银小云-提现-收益账户
//            return AccountType.getFullCode(AccountType.ALLY_PROFIT_WITHDRAW, platNo);
//        } else if (PayFromEnum.client_admin_withdraw.isEquals(withdrawType)) {                   //银小云-提现-下游终端后台提现
//            return AccountType.getFullCode(AccountType.ALLY_WITHDRAW, platNo);
//        } else if (PayFromEnum.client_admin_withdraw_profit.isEquals(withdrawType)) {                   //银小云-提现-下游终端后台提现-分润
//            return AccountType.getFullCode(AccountType.ALLY_PROFIT_WITHDRAW, platNo);
        } else if (PayFromEnum.yxy_withdraw_ally_all.isEquals(withdrawType)) {//银小云-提现-盟友合并提现
            return AccountType.getFullCode(AccountType.SYS_V2_WITHDRAW, platNo);
        }
        throw new UserBizException(BizCodeMessages.WITHDRAW_TYPE_OFF);

    }

    /**
     * 获取 用户-提现账户类型
     *
     * @param withdrawType 提现类型类型
     * @return 用户提现账户类型
     * @see AccountType
     */
    public static Integer formatUserAccountType(String withdrawType, Short platNo) {
//        if (PayFromEnum.commission.isEquals(withdrawType)                                           //银行卡推广返佣提现
//                || PayFromEnum.zyj_commission.isEquals(withdrawType)
//                || PayFromEnum.yxy_commission.isEquals(withdrawType)) {                             //众赢嘉-银行卡推广返佣提现
//            return AccountType.getFullCode(AccountType.CREDIT_COMMISSION, platNo);
//        } else if (PayFromEnum.taobao_score.isEquals(withdrawType)                                  //积分购物返利提现
//                || PayFromEnum.zyj_taobao_score.isEquals(withdrawType)) {                           //众赢嘉-积分购物返利提现
//            return AccountType.getFullCode(AccountType.SHOPPING_SCORE, platNo);
//        } else

        if (PayFromEnum.yxy_withdraw_mer.isEquals(withdrawType)) {                           //银小云-提现-商户账户
            return AccountType.getFullCode(AccountType.MER, platNo);
        } else if (PayFromEnum.withdraw_ally.isEquals(withdrawType)                                 //提现-盟友账户
                || PayFromEnum.yxy_withdraw_ally.isEquals(withdrawType)) {                          //银小云-提现-盟友账户
            return AccountType.getFullCode(AccountType.ALLY, platNo);
//        } else if (PayFromEnum.withdraw_ally_reach.isEquals(withdrawType)                           //提现-达标奖励账户
//                || PayFromEnum.zyj_withdraw_ally_reach.isEquals(withdrawType)                       //众赢嘉-提现-达标奖励账户
//                || PayFromEnum.yxy_withdraw_ally_reach.isEquals(withdrawType)) {                    //银小云-提现-达标奖励账户
//            return AccountType.getFullCode(AccountType.ALLY_REACH, platNo);
//        } else if (PayFromEnum.withdraw_conversion.isEquals(withdrawType)) {                        //提现-兑换金账户
//            return AccountType.getFullCode(AccountType.CONVERSION, platNo);
//        } else if (PayFromEnum.yxy_sub_teanm.isEquals(withdrawType)) {                        //提现-兑换金账户
//            return AccountType.getFullCode(AccountType.SUB_TEAM_ACTION, platNo);
//        } else if (PayFromEnum.withdraw_ally_profit.isEquals(withdrawType)                          //提现-收益账户
//                || PayFromEnum.zyj_ally_profit.isEquals(withdrawType)                               //众赢嘉-提现-收益账户
//                || PayFromEnum.yxy_withdraw_ally_profit.isEquals(withdrawType)) {                   //银小云-提现-收益账户
//            return AccountType.getFullCode(AccountType.ALLY_PROFIT, platNo);
//        } else if (PayFromEnum.client_admin_withdraw.isEquals(withdrawType)) {                   //银小云-提现-下游终端后台提现
//            return AccountType.getFullCode(AccountType.ALLY, platNo);
//        } else if (PayFromEnum.client_admin_withdraw_profit.isEquals(withdrawType)) {                   //银小云-提现-下游终端后台提现-分润
//            return AccountType.getFullCode(AccountType.ALLY_PROFIT, platNo);
        } else if (PayFromEnum.yxy_withdraw_ally_all.isEquals(withdrawType)) {//银小云-提现-盟友合并提现
            return AccountType.getFullCode(AccountType.ALLY_V2, platNo);
        }
        throw new UserBizException(BizCodeMessages.WITHDRAW_TYPE_OFF);

    }


        /**
     * 获取 账单类型
     *
     * @param withdrawType 提现类型
     * @return 系统提现账户流水类型
     * @see FundBillType
     */
    public static FundBillType formatFundBillTypeV2(String withdrawType) {
        return FundBillType.TYPE_200;
    }
    /**
     * 获取 账单类型
     *
     * @param withdrawType 提现类型
     * @return 系统提现账户流水类型
     * @see FundBillType
     */
    public static FundBillType formatFundBillType(String withdrawType) {
//        if (PayFromEnum.commission.isEquals(withdrawType)                               //银行卡推广返佣提现
//                || PayFromEnum.zyj_commission.isEquals(withdrawType)|| PayFromEnum.yxy_commission.isEquals(withdrawType)) {                 //众赢嘉-银行卡推广返佣提现
//            return FundBillType.TYPE_210;
//        } else if (PayFromEnum.taobao_score.isEquals(withdrawType)                      //积分购物返利提现
//                || PayFromEnum.zyj_taobao_score.isEquals(withdrawType)) {               //众赢嘉-积分购物返利提现
//            return FundBillType.TYPE_220;
//        } else

            if (PayFromEnum.yxy_withdraw_mer.isEquals(withdrawType)) {               //银小云-提现-商户账户
            return FundBillType.TYPE_200;
        } else if (PayFromEnum.withdraw_ally.isEquals(withdrawType)                     //提现-盟友账户
                || PayFromEnum.yxy_withdraw_ally.isEquals(withdrawType)) {              //银小云-提现-盟友账户
            return FundBillType.TYPE_200;
//        } else if (PayFromEnum.withdraw_ally_reach.isEquals(withdrawType)               //提现-达标奖励账户
//                || PayFromEnum.zyj_withdraw_ally_reach.isEquals(withdrawType)           //众赢嘉-提现-达标奖励账户
//                || PayFromEnum.yxy_withdraw_ally_reach.isEquals(withdrawType)) {        //银小云-提现-达标奖励账户
//            return FundBillType.TYPE_230;
//        } else if (PayFromEnum.withdraw_conversion.isEquals(withdrawType)) {            //提现-兑换金账户
//            return FundBillType.TYPE_250;
//        }  else if (PayFromEnum.yxy_sub_teanm.isEquals(withdrawType)) {            //提现-兑换金账户
//            return FundBillType.TYPE_260;
//        } else if (PayFromEnum.withdraw_ally_profit.isEquals(withdrawType)              //提现-收益账户
//                || PayFromEnum.zyj_ally_profit.isEquals(withdrawType)                   //众赢嘉-提现-收益账户
//                || PayFromEnum.yxy_withdraw_ally_profit.isEquals(withdrawType)) {       //银小云-提现-收益账户
//            return FundBillType.TYPE_240;
//        } else if (PayFromEnum.client_admin_withdraw.isEquals(withdrawType)) {       //银小云-提现-下游终端后台提现
//            return FundBillType.TYPE_200;
//        } else if (PayFromEnum.client_admin_withdraw_profit.isEquals(withdrawType)) {       //银小云-提现-下游终端后台提现-分润
//            return FundBillType.TYPE_240;
        } else if (PayFromEnum.yxy_withdraw_ally_all.isEquals(withdrawType)) {       //银小云-提现-盟友合并提现
            return FundBillType.TYPE_200;
        }
        throw new UserBizException(BizCodeMessages.WITHDRAW_TYPE_OFF);
    }

    /**
     * 获取提现费率、手续费
     */
    public static WithdrawInAmountFeeVO withdrawInAmountFeeVO(Integer fullAccountType) {
        return withdrawInAmountFeeVO(fullAccountType, null);
    }
    public static WithdrawInAmountFeeVO withdrawInAmountFeeVO(Integer fullAccountType, String withdrawType) {
        WithdrawInAmountFeeVO feeVO = new WithdrawInAmountFeeVO();
        //商户资金、兑换金手续费8%,没有秒提费
        if (AccountType.MER.isEqualsFullAccountNo(fullAccountType)
                || AccountType.MERCHANT_FROM_BOSS.isEqualsFullAccountNo(fullAccountType)
                || AccountType.CONVERSION.isEqualsFullAccountNo(fullAccountType)) {
            feeVO.setWithdrawFixedAmt(BigDecimal.ZERO);
        }

        //基梯后台提现，手续费固定为2
//        if(StringUtils.isNotEmpty(withdrawType) &&
//                (PayFromEnum.client_admin_withdraw.getCode().equals(withdrawType) || PayFromEnum.client_admin_withdraw_profit.getCode().equals(withdrawType))){
//            feeVO.setWithdrawRate(BigDecimal.ZERO);
//            feeVO.setWithdrawFixedAmt(new BigDecimal("2"));
//        }
        return feeVO;
    }

    /**
     * 提现描述
     */
    public static String formatWithdrawBody(Short platNo) {
        if (PlatNoEnums.ZYJ.isEquals(platNo)) {
            return "众赢嘉";
        } else if (PlatNoEnums.YXY.isEquals(platNo)) {
            return "银小云";
        } else {
            return "考拉快收";
        }
    }

    /**
     * 生成订单号
     */
    public static String genOrderNo(String orderPrefix) {
        return orderPrefix + DateFormat.DATETIME_MILLISECOND_COMPACT.format(LocalDateTime.now()) + RandomStringUtils.randomNumeric(5);
    }
}
